<%@ page language="java" pageEncoding="utf-8"%>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 	<link rel="stylesheet" href="<%=request.getContextPath() %>/resources/validform/css/demo.css" type="text/css"></link>
	<link rel="stylesheet" href="<%=request.getContextPath() %>/resources/validform/css/style.css" type="text/css"></link>
 	<link rel="stylesheet" href="<%=request.getContextPath() %>/resources/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css"></link>
 	<script type="text/javascript" src="<%=request.getContextPath() %>/resources/js/jquery-1.9.1.min.js"></script>
 	<script type="text/javascript" src="<%=request.getContextPath() %>/resources/zTree/js/jquery.ztree.core-3.5.js"></script>
    <SCRIPT type="text/javascript" >
	var setting = {data: {simpleData: {enable: true}}	};
	var zTree ;
	$.ajax({
 		    url: "<%=request.getContextPath() %>/functionMenu!searchFunctionMenu.action",type: "post", dataType: "json", 
 		    success: function (data, textStatus) {  
 		   	 	var json = eval("(" + data + ")");
 		   	 	 if (json.STATUS > 0) { 
 		   	 		$.fn.zTree.init($("#tree"), setting, json.functionMenu);
 		   	 	}else{
 		   	 		alert("加载菜单失败!");
 		   	 	}
 		     },
 		    beforeSend: function () {},
 		    error: function (XMLHttpRequest, textStatus, errorThrown) {alert("操作失败!"); },
 		    complete: function (XMLHttpRequest, textStatus, errorThrown) {zTree= $.fn.zTree.getZTreeObj("tree");  }
 		});
  </SCRIPT>
    
  </head>
  
  <body>
    <form id="myForm" name="myform"  class="myform" action="" suc_url="<%=request.getContextPath() %>/functionMenu!toFunctionMenu.action" enctype="multipart/form-data"> 
    <table>
    	<tr>
    		<td width="300px;"><div  id="tree" class="ztree" ></div></td>
    		<td>
	    		 <input id="addTJCD" value="新增同级菜单" type="button"  />  
			   	 <input id="addXJCD" value="新增下级菜单"  type="button" />
			   	 <input id="updateXZCD" value="修改选中菜单"  type="button" />
			   	 <input id="deleteXZCD"value="删除选中菜单"  type="button" />
		   	 </td>
    	</tr>
    	<tr>
    		<td>&nbsp;</td>
    		<td>
	    		 <table>
	    			 <tr>
	    		 		<td colspan="3" ><div id="show_opname"></div></td>
	    		 	</tr>
	    		 	<tr>
	    		 		<td>菜单名</td>
	    		 		<td><input id="menuname" name="menuname" class="inputxt" type="text" datatype="*"  /></td>
	    		 		<td class="Validform_checktip"></td>
	    		 	</tr>
	    		 	<tr>
	    		 		<td>图标</td>
	    		 		<td>
	    		 			<div id="image_file">
	    		 				<input id="image" name="image"  type="file" class="inputxt"  />
	    		 			</div> 
	    		 			<input id="deleteImage" name="deleteImage"  type="button" style="width: 100px;height: 40px;" value="删除图片" />
    		 				<img   src="" id="image_show"  style="display:none;">
    		 				<input id="image_name" name="image_name"  type="hidden" value="" /> 
	    		 		</td>
	    		 		<td class="Validform_checktip"></td>
	    		 	</tr>
	    		 	<tr>
	    		 		<td>跳转地址</td>
	    		 		<td><input id="url" name="url"  type="text" class="inputxt"  /></td>
	    		 		<td class="Validform_checktip"></td>
	    		 	</tr>
	    		 	<tr>
	    		 		<td>标题</td>
	    		 		<td><input id="title" name="title"  type="text" class="inputxt"  /></td>
	    		 		<td class="Validform_checktip"></td>
	    		 	</tr>
	    		 	<tr>
	    		 		<td>是否启用</td>
	    		 		<td>
	    		 			<select id="enable" name="enable" >
		 						<option value="1">启用</option>
		 						<option value="0">禁用</option>
 							</select>
	    		 		</td>
	    		 		<td class="Validform_checktip"></td>
	    		 	</tr>
	    		 	<tr>
	    		 		<td>排序</td>
	    		 		<td><input id="orderid" name="orderid"  type="text" class="inputxt"  ignore="ignore" datatype="n" errormsg="请输入数字排序"  /></td>
	    		 		<td class="Validform_checktip"></td>
	    		 	</tr>
	    		 		<tr>
	    		 		<td>描述</td>
	    		 		<td><textarea  id="descrip" name="descrip"></textarea></td>
	    		 		<td class="Validform_checktip"></td>
	    		 	</tr>
    		 		<tr>
	    		 		<td colspan="3"  > <input id="btn_sub" value="提交" class="ajaxpost" type="submit"  /> <input value="重置"  type="reset" /></td>
	    		 	</tr>
	    		 </table>
		   	 </td>
    	</tr>
    </table>
    <input  type="hidden" id="pid" name="pid" value="">
    </form>
<script type="text/javascript">
	//新增同级菜单
	$("#addTJCD").click(function(){
		if(validSelectMenu("新增同级菜单")){
			nodes = zTree.getSelectedNodes();
			if(nodes[0].pId==null){$("#pid").val("0"); }else{$("#pid").val(nodes[0].pId);}//设置pid 的值
			$("#myForm").attr("action","<%=request.getContextPath() %>/functionMenu!addFunctionMenu.action");//设置myForm 的 action  
		}
	});
	
	//新增下级菜单
	$("#addXJCD").click(function(){
		if(validSelectMenu("新增下级菜单")){
			nodes = zTree.getSelectedNodes();
			$("#pid").val(nodes[0].id); //设置pid 的值
			$("#myForm").attr("action","<%=request.getContextPath() %>/functionMenu!addFunctionMenu.action");
			//设置myForm 的 action  
		}
	});
	//修改选中菜单
	$("#updateXZCD").click(function(){
		if(validSelectMenu("修改选中菜单")){
			nodes = zTree.getSelectedNodes();
			//查询 菜单详情
			$.ajax({
	 		    url: "<%=request.getContextPath() %>/functionMenu!detalisFunctionMenu.action?id="+nodes[0].id,type: "post", dataType: "json", 
	 		    success: function (data, textStatus) {  var json = eval("(" + data + ")"); 
 		   	    	if (json.STATUS > 0) {  //设置 文本框的值
						$("#menuname").val(json.map.menuname);
						if(json.map.icon!=null && json.map.icon!=""){
							$("#image_show").attr("src","<%=request.getContextPath() %>"+json.map.icon);
							$("#image_show").css("display","block");
							$("#image_name").val(json.map.icon);
						}
						$("#url").val(json.map.url);
						$("#title").val(json.map.title);
						$("#description").val(json.map.description);
						$("#pid").val(json.map.pid);
						$("#enable").val(json.map.enable);
						$("#enable").find("option[value="+json.map.enable+"]").attr("selected",true);
						$("#orderid").val(json.map.orderid);
						$("#myForm").attr("action","<%=request.getContextPath() %>/functionMenu!updateFunctionMenu.action?id="+json.map.id);
					}
	 		      },
	 		    beforeSend: function () {},
	 		    error: function (XMLHttpRequest, textStatus, errorThrown) {alert("操作失败!"); },
	 		    complete: function (XMLHttpRequest, textStatus, errorThrown) {  }
 			});
		}
	});
	$("#deleteImage").click(function (){
		$("#image_show").css("display","none");
		$("#image_show").attr("src","");
		//$("#image_name").val("");
		$("#image_file").html("<input id='image' name='image'  type='file' class='inputxt'  />");
	});
	
	
	//删除下级菜单
	$("#deleteXZCD").click(function(){
		if(validSelectMenu("删除选中菜单?")){
			nodes = zTree.getSelectedNodes();
			detele("是否删除选中菜单以及下级菜单?","<%=request.getContextPath() %>/functionMenu!deleteFunctionMenu.action?id="+nodes[0].id,$("#myForm").attr("suc_url"));
		}
	});
	
	//验证是否选中菜单
	function validSelectMenu(show_opname){
			nodes = zTree.getSelectedNodes();
			if (nodes.length == 0) {alert("请先选择一个节点");return false;}
			$("#show_opname").html(show_opname);
			return true;
	}
	
</script>
<script type="text/javascript"  src="<%=request.getContextPath() %>/resources/js/jquery.form.js"></script>
<script type="text/javascript"  src="<%=request.getContextPath() %>/resources/validform/js/Validform_v5.3.2.js"></script>
<script type="text/javascript"  src="<%=request.getContextPath() %>/resources/js/opform.js"></script>
<script type="text/javascript"  src="<%=request.getContextPath() %>/resources/js/common.js"></script>
 
